/*
 * @lc app=leetcode.cn id=1232 lang=golang
 * @lcpr version=30118
 *
 * [1232] 缀点成线
 */

// @lcpr-template-start
package main

import (
	"fmt"
	"math"
)

func main() {
	coordinates := [][]int{{1, 1}, {2, 2}, {3, 4}, {4, 5}, {5, 6}, {7, 7}}
	result := checkStraightLine(coordinates)
	fmt.Println(result)
}

// @lcpr-template-end
// @lc code=start
func checkStraightLine(coordinates [][]int) bool {
	nrows := len(coordinates)
	if nrows == 2 {
		return true
	}
	if coordinates[0][0] == coordinates[1][0] {
		for i := 1; i < nrows; i++ {
			if coordinates[i][0] != coordinates[0][0] {
				return false
			}
		}
		return true
	} else {
		k := float64(coordinates[1][1]-coordinates[0][1]) / float64(coordinates[1][0]-coordinates[0][0])
		for i := 1; i < nrows; i++ {
			if math.Abs(float64(coordinates[i][0]-coordinates[0][0])*k-float64(coordinates[i][1]-coordinates[0][1])) > float64(1e-9) {
				return false
			}
		}
		return true
	}
}

// @lc code=end

/*
// @lcpr case=start
// [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]\n
// @lcpr case=end

// @lcpr case=start
// [[1,1],[2,2],[3,4],[4,5],[5,6],[7,7]]\n
// @lcpr case=end

*/
